unit ParamUtil;

interface
uses
  Classes;

function getSwitch(Param: TStringList; Switch: Char): String; overload;
function getCommand(Param: TStringList; Command: Char): Boolean;

function getSwitch(Param: TStringList; Switch: String): String; overload;

implementation

function getSwitch(Param: TStringList; Switch: Char): String;
var
  i: Integer;
  tmpS: String;
begin
  Result := '';

  for i := 0 to Param.Count - 1 do begin
    tmpS := Param[i];
    if (Length(tmpS) >= 2) and ((tmpS[1] = '-') or (tmpS[1] = '\')) and (tmpS[2] = Switch) then begin
      Result := tmpS;
      Delete(Result, 1, 2);
    end;

  end;
end;

function getCommand(Param: TStringList; Command: Char): Boolean;
var
  i: Integer;
  tmpS: String;
begin
  Result := False;

  for i := 0 to Param.Count - 1 do begin
    tmpS := Param[i];
    if (Length(tmpS) >= 2) and ((tmpS[1] = '-') or (tmpS[1] = '\')) and (tmpS[2] = Command) then begin
      Result := True;
      exit;
    end;
  end;
end;

//------------------------------------------------------------------------------
//  Format
//    Switch=Value
//
//  Result
//    Returns the Value
//
//------------------------------------------------------------------------------
function getSwitch(Param: TStringList; Switch: String): String; overload;
var
  ctr, es: Integer;
  tmpS, ss: String;
begin
  Result := '';

  for ctr := 0 to Param.Count - 1 do begin
    tmpS := Param[ctr];

    es := Pos('=', tmpS);
    if es > 0 then begin
      ss := Copy(tmpS, 1, es-1);
      if ss = Switch then begin
        Result := Copy(tmpS, es+1, Length(tmpS)-es);
        exit;
      end;
    end;
  end;
end;

end.
